#!/bin/sh

Makefile_in="Makefile.in"

OS=$(uname -s)

case $OS in
FreeBSD|NetBSD|OpenBSD)
    INSTALL="/usr/bin/install -c"
    [ -z "$PREFIX" ] && PREFIX='${DESTDIR}/usr/local'
    INSTALL_DIROPT=""
    INSTALL_OWNER="-o "
    PERM_BINARY="-m 755"
    PERM_DIR="-m 644"
;;
GNU|LINUX|Linux)
    INSTALL="/usr/bin/install -c"
    [ -z "$PREFIX" ] && PREFIX='${DESTDIR}/usr'
    INSTALL_DIROPT="-D"
    INSTALL_OWNER="-o "
    PERM_BINARY="-m 755"
    PERM_DIR="-m 644"
;;
CYGWIN*)
    INSTALL="/usr/bin/install -c"
    [ -z "$PREFIX" ] && PREFIX='${DESTDIR}/usr'
    INSTALL_DIROPT="-D"
    INSTALL_OWNER=""
    PERM_BINARY=""
    PERM_DIR=""
;;
esac

sed -e "s:[$][$]INSTALL[$][$]:$INSTALL:g"\
    -e "s:[$][$]PREFIX[$][$]:$PREFIX:g"\
    -e "s:[$][$]INSTALL_DIROPT[$][$]:$INSTALL_DIROPT:g" \
    -e "s:[$][$]INSTALL_OWNER[$][$]:$INSTALL_OWNER:g" \
    -e "s:[$][$]PERM_BINARY[$][$]:$PERM_BINARY:g" \
    -e "s:[$][$]PERM_DIR[$][$]:$PERM_DIR:g" \
    $Makefile_in > Makefile
